﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenExpressApp.Template;

namespace OpenExpressApp.Module.WPF.Templete
{
    /// <summary>
    /// 所有IFrameController的基类
    /// </summary>
    public abstract class BaseListFrameController : IFrameController
    {
        private IFrameTemplate _frameTemplate;

        public BaseListFrameController(IFrameTemplate frameTemplate)
        {
            if (frameTemplate == null) throw new ArgumentNullException("frameTemplate");

            this._frameTemplate = frameTemplate;
        }

        public ListObjectView View
        {
            get
            {
                return this._frameTemplate.View as ListObjectView;
            }
        }

        public IFrameTemplate FrameTemplate
        {
            get
            {
                return this._frameTemplate;
            }
        }

        /// <summary>
        /// 执行自动的命令
        /// </summary>
        public static void ExecAutoCommands(Type entityType, ObjectView view)
        {
            foreach (var c in ApplicationModel.Commands.Where(c => c.AutoExecuting))
            {
                if (c.TargetObjectType == entityType || c.TargetObjectType == null)
                {
                    c.Execute(view);
                }
            }
        }
    }
}
